﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using ww.form.wwf.RdlcPrint;
using System.Xml;
using ww.wwf.wwfbll;

namespace ww.form.lis.sam.jy
{
    public partial class Form_dysz : ww.form.wwf.SysBaseForm
    {
        public Form_dysz()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form_dysz_Load(object sender, EventArgs e)
        {
            PrinterSettings.StringCollection snames = PrinterSettings.InstalledPrinters;
            string str_def = Printer.GetDeaultPrinterName();
            foreach (string s in snames)
            {
                lbxPrinter.Items.Add(s);
            }
            label1.Text = "默认打印机："+str_def;
            
            
        }

        private void lbxPrinter_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Printer.SetPrinterToDefault(lbxPrinter.SelectedItem.ToString().Trim());
            //label1.Text = "默认打印机：" + lbxPrinter.SelectedItem.ToString().Trim();
        }

        private void lbxPrinter_DoubleClick(object sender, EventArgs e)
        {
            if (object.Equals(null, lbxPrinter.SelectedItem)) return;

            string str_print = lbxPrinter.SelectedItem.ToString().Trim();
            string xmlPath = Application.StartupPath + @"/WWReporName.config";
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlPath);
            foreach (XmlNode node1 in xmlDoc.ChildNodes)
            {
                foreach (XmlNode node2 in node1.ChildNodes)
                {
                    foreach (XmlNode xnode in node2.ChildNodes)
                    {
                        XmlElement element = (XmlElement)xnode;
                        if (element.Name == "PrinterName")
                            element.InnerText = str_print;
                    }
                }
            }
            xmlDoc.Save(xmlPath);
            WWMessage.MessageShowInformation("更新成功为：【" + str_print + "】");
        }
    }
}